package handler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import entity.User;

public class UserHandler 
{
private static CustomerHandler instance = null;
	
	String url = "jdbc:mysql://localhost:3306/vcp";
    String user = "root";
    String sqlPassword = "";
    
    
	
	public User loadUser(int uid){
		
		Connection con = null;
        PreparedStatement st = null;
        ResultSet rs = null;
        
        User loadUser = null;
        //Customer cust = null;
        
        try {
        	
        	
            con = DriverManager.getConnection(url, user, sqlPassword);
            st = con.prepareStatement("select * from user u where u.uid = ?");
            
            st.setString(1, uid+"");
            //st.setString(2, password);
            
            rs = st.executeQuery();
            
            if (rs.next()) {
            	
            	//System.out.println(rs.getString(2));
            	loadUser = new User();
            	loadUser.setUid(new Integer(rs.getString(1)).intValue());
            	loadUser.setFirstname(rs.getString(2));
            	loadUser.setLastname(rs.getString(3));
            	loadUser.seteMail(rs.getString(4));
            	loadUser.setPhone(rs.getString(5));        	
            }

            con.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        //return cust;
		
		return loadUser;
	}
}
